using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class JobSeekers_JobResults : System.Web.UI.Page
{
    string typeName = "";
    string typeID = "";
    string typeValue = "";
    string typeUrl = "";
    protected void Page_Load(object sender, EventArgs e)
    {

        
        if(!IsPostBack)
        {
            typeID = Request.QueryString.Get("ID");
            typeName = Request.QueryString.Get("type");
            typeValue = Request.QueryString.Get("value");
            typeUrl = Request.QueryString.Get("page");
            if (typeID != null && typeID != "")
            {
                litID.Text = typeID;
                litValue.Text = typeValue;
                litType.Text = typeName;
                litUrl.Text = typeUrl;
                ShowResult(typeID, typeName);             
            }
        }
        else
        {
            typeID = litID.Text;
            typeName = litType.Text;
            typeValue = litValue.Text;
            typeUrl = litUrl.Text;
        }
        if (typeID == "" || typeID == null || typeName == "" || typeName == null)
            Response.Redirect("search.aspx");
        Literal1.Text  = "  <input type=button " +
                    "value='Back' " +
                    "onclick =\"window.history.go(-1);\">";
    }
    void ShowResult(string typeID, string typeName)
    {
        try{
            ControlHelper cls = new ControlHelper("");
            cls.CommandText = "SPJobList";
            cls.ParameterCollection = new string[2] { "@typeID", "@typeName"};
            cls.ValueCollection = new string[2] { typeID, typeName };
            cls.CommandType = CommandType.StoredProcedure;
            cls.InitProperties();
            cls.FillDataTableToGridView(this.GridView1, 15, 10, PagerButtons.NumericFirstLast);
            FillUrl(this.GridView1, typeUrl);
        }
        catch(Exception ex)
        {
            litError.Text = ex.Message;
        }
    }

    void FillUrl(GridView GridView1, string backUrl)
    {
        foreach(GridViewRow gridViewRow in GridView1.Rows)
        {
            HyperLink  hyperLinkField =
            (HyperLink )gridViewRow.Cells[1].Controls[0];
            hyperLinkField.NavigateUrl =
           hyperLinkField.NavigateUrl + "&page=" + backUrl;
        }
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        ShowResult(typeID, typeName);  
        
    }

     
}
